<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
   <title>FishVideo信息管理平台</title>
   <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
   <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
   <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
  <style>
	.table th{
		text-align:center;
	}
	.table td{
		text-align:center;
	}
	#left{
		width:20%;
		float:left;
	}
	#content{
		width:80%;
		margin-left:20%;
	}
	#info{
		font-size:20px;
	}
	#add{
		float:right;
	}
	 #pageButton{
			width:80%;
			margin-left:10%;
	   }
	   #leftbutton{
			width:50%;
			
	   }
	   #rightbutton{
			width:50%;
			margin-left:50%;
			
	   }
  </style>
</head>
<body>
<?php require_once("control_daohang.php")?>
	<div class="container" id=left>
	<?php require_once("menu.html");?>
	</div>
	<div id="content">
		<div id="add"><a href="#" data-toggle="modal"  data-target="#register">添加分类&nbsp&nbsp&nbsp</a></div>
		<table class="table">
		<tr><th>序号</th><th>名称</th><th>操作</th></tr>
			<?php
				require_once("../utils/upload.php");
				require_once("../utils/db.php");
				$conn=connect();
			?>
			<?php			
			//所有type信息的输出
			if(isset($_GET['del'])){//如果删除
				$sql="delete from fishvideo_videotype where yjl_tid='{$_GET['del']}';";
				//echo $sql;
				if(!mysql_query($sql,$conn)){
					echo "<script>alert('删除失败!');</script>";
				}
			}
			if(isset($_POST['addtype'])){//如果添加分类
				$sql="insert into fishvideo_videotype values(null,'{$_POST['typename']}');";
				//echo $sql;
				if(!mysql_query($sql,$conn)){
					echo "<script>alert('添加失败!');</script>";
				}
			}
			if(isset($_POST['changebut'])){//执行了修改操作
				$sql="update fishvideo_videotype set yjl_typename='{$_POST['ctypename']}' where yjl_tid={$_POST['tid']}";
				if(!mysql_query($sql,$conn)){
					echo "<script>alert('修改失败!');</script>";
				}else{
					$url="control_videotype.php";
					echo "<meta http-equiv='Refresh' content='0;URL={$url}'>"; //跳转界面
				}
			}
			$sql="select * from fishvideo_videotype";
			if(isset($_POST['search'])){//查询
				$sql.=" where yjl_typename like '%{$_POST['videoname']}%' ";
			}
			//echo $sql;
			$result=mysql_query($sql,$conn);
			$sumnumber=mysql_num_rows($result);
			//分页
			if(!isset($_GET['page'])){//如果没有
					$page=0;
				}else{
					$page=$_GET['page'];
				}
				$perpage=10;//每页10个
				$pagenumberq=$page*10;
				$sql.=" limit {$pagenumberq},{$perpage}";
				//echo $sql;
				$ym=($pagenumberq+$perpage);
				if($ym>($sumnumber)) $ym=($sumnumber);
			$result=mysql_query($sql,$conn);
			for($ct=($pagenumberq+1);$ct<=$ym;$ct++){
				$row=mysql_fetch_array($result);
				echo "<tr><td>{$ct}</td>";
				
				if(isset($_GET['change'])){
					echo "<form method='post'><input type='hidden' name='tid' value='{$row['yjl_tid']}'>";
					echo "<td><input type='text' name='ctypename' class='form-control' value='{$row['yjl_typename']}'></td>";
					echo "<td><input type='submit' name='changebut' class='btn btn-default' value='修改'></form>";
				}else{
					echo "<td>{$row['yjl_typename']}</td>";
					echo "<td><a href='control_videotype.php?change='cc''>修改</a>";
				}
				echo "<a onclick=\"confirm('确定要删除吗')?
			location.href='control_videotype.php?del={$row['yjl_tid']}':''\"
				href=\"javascript:;\"> | 删除</a></td>";
			}	
			mysql_close($conn);
			?>
<tr>
<!--分页 -->
	  <div id="dispage">
		<span>
		 <?php
			if($sumnumber%$perpage==0)
			$sumpage=(int)($sumnumber/$perpage);
			else $sumpage=(int)(($sumnumber/$perpage)+1);
				$now =$page+1;
		    echo "共有{$sumnumber}条数据，当前第({$now}/{$sumpage})页";
		?>
		</span>
		<span>
		<?php
		echo "<a href='control_user.php?page=0'>首页</a> ";
		if($page!=0){
		$now = $page-1;
		echo "<a href='control_user.php?page={$now}'>上一页</a> ";
		}
		if($page!=($sumpage-1)){
			$now = $page+1;
		echo "<a href='control_user.php?page={$now}'>下一页</a> ";
		}
		$now=$sumpage-1;
		echo "<a href='control_user.php?page={$now}'>尾页</a>";
		?>
		</span>
	</div>		
	</tr>
		</table>
	</div>
	
	<!-- 模态框（Modal）（注册） -->
<div class="modal fade" id="register" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
	   <div class="modal-dialog">
		  <div class="modal-content">
			 <div class="modal-header">
				<button type="button" class="close" 
				   data-dismiss="modal" aria-hidden="true">
					  &times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
				   请填写分类信息
				</h4>
			 </div>
			 <!--登陆主体 -->
			 <div class="modal-body">
		<form role="form"  method="post" enctype="multipart/form-data">
		<table class="table" align="center">
		<tr><th>分类名称</th><td><input type="text" class="form-control" id="name" name="typename"
		required oninvalid="setCustomValidity('请填写姓名')"
					oninput="setCustomValidity('')"></td></tr>			
	</table>
	<div id="pageButton">
		<span id="leftbutton">
		<button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
		</span>
		<span id="rightbutton">
            <button type="submit" name="addtype" class="btn btn-primary">
               添加
            </button>
		</span>
    </div>
	 </form>
	 </div>
	</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</body>
</html>